package com.xuan.commons.api;

import lombok.Data;

import java.io.Serializable;

/**
 * @author renzhengxuan
 * @date 2021/5/16
 * 接口返回对象
 */
@Data
public class R<T> implements Serializable {
    private Integer code;
    private String msg = "操作成功";
    private boolean success = true;
    private T date; //返回数据对象

    public R<T> error500(String msg){
        this.msg=msg;
        this.code = 500;
        this.success = false;
        return this;
    }
    public R<T> success(String msg){
        this.msg=msg;
        this.code = 200;
        this.success = true;
        return this;
    }

    public static R<Object> error(String msg){
        R r = new R();
        r.setMsg(msg);
        r.setCode(500);
        r.setSuccess(false);
        return r;
    }
    public static R<Object> ok(String msg){
        R r = new R();
        r.setMsg(msg);
        r.setCode(200);
        r.setSuccess(true);
        return r;
    }
    public static R<Object> noAuto(String msg){
        R r = new R();
        r.setMsg(msg);
        r.setCode(401);
        r.setSuccess(false);
        return r;
    }
    public static R<Object> date(Object date){
        R r = new R();
        r.setMsg("操作成功");
        r.setCode(200);
        r.setSuccess(true);
        r.setDate(date);
        return r;
    }
}
